﻿using System;
using System.Data;
using Ue.Framework.Data;
using Ue.Infrastructure.EntityFactoryFramework;
using Ue.Qcdz.Domain.Membership;
using Ue.Qcdz.Domain;

namespace Ue.Qcdz.Repositories.Membership
{
    internal class UserFactory : IEntityFactory<User>
    {
        internal class FieldNames : FieldNamesBase
        {
            public const string UserName = "UserName";
            public const string Password = "Password";
            public const string PasswordQuestion = "PasswordQuestion";
            public const string PasswordOtherQuestion = "PasswordOtherQuestion";
            public const string PasswordAnswer = "PasswordAnswer";
            public const string LastLoginDate = "LastLoginDate";
            public const string State = "State";
            public class ProfileFieldNames
            {
                public const string UserInProfileKey = "UserId";
                public const string Name = "Name";
                public const string Sex = "Sex";
                public const string MobilePhone = "MobilePhone";
                public const string Telephone = "Telephone";
                public const string Fax = "Fax";
                public const string CityId = "CityId";
                public const string Street = "Street";
                public const string PostalCode = "PostalCode";
                public const string Company = "Company";
                public const string CompanyAddress = "CompanyAddress";
                public const string QQnumber = "QQnumber";
                public const string UserAddress = "UserAddress";
                public const string Birthday = "Birthday";
                public const string Email = "Email";
            }
        }

        #region IEntityFactory

        public User BuildEntity(IDataReader reader)
        {
            return new UserProxy(
                reader.Get<Guid>(FieldNames.EntityKey),
                reader.Get<string>(FieldNames.UserName),
                reader.Get<string>(FieldNames.Password),
                reader.Get<PasswordQuestion>(FieldNames.PasswordQuestion),
                reader.Get<string>(FieldNames.PasswordOtherQuestion),
                reader.Get<string>(FieldNames.PasswordAnswer),
                reader.Get<DateTime>(FieldNames.CreateOn),
                reader.Get<EntityState>(FieldNames.State)
               );

        }

        #endregion
    }
}
